package com.yegs.jltqc.controller;

import com.yegs.jltqc.TO.NamePageQuery;
import com.yegs.jltqc.TO.RpproducePageQuery;
import com.yegs.jltqc.VO.QcProduce;
import com.yegs.jltqc.VO.RpProduce;
import com.yegs.jltqc.config.Msg;
import com.yegs.jltqc.service.QcProduceService;
import com.yegs.jltqc.service.RpProduceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/rpProduce")
public class RpProduceController {

    @Autowired
    private RpProduceService rpProduceService;

    @PostMapping("/save")
    public Msg save(@RequestBody RpProduce rpProduce){
        try{
            RpProduce rpproduce = rpProduceService.save(rpProduce);
            return Msg.success("rpproduce",rpproduce);
        }catch (Exception e){
            e.printStackTrace();
            return Msg.error(e.getMessage());
        }
    }

    @GetMapping("/list")
    public Msg list(){
        return Msg.success("list",rpProduceService.list());
    }

    @GetMapping("/get")
    public Msg get(@RequestParam Long id){
        return Msg.success("data", rpProduceService.get(id));
    }
    @GetMapping("/del")
    public Msg del(@RequestParam Long id){
        rpProduceService.del(id);
        return Msg.success();
    }
    @GetMapping("/getLast")
    public Msg getLast(@RequestParam(required = false) Long id){
        return Msg.success("data",rpProduceService.getLast(id));
    }
    @GetMapping("/getNext")
    public Msg getNext(@RequestParam(required = false) Long id){
        return Msg.success("data",rpProduceService.getNext(id));
    }

    @PostMapping("/query")
    public Msg query(@RequestBody RpproducePageQuery query){
        return Msg.success("page",rpProduceService.query(query));
    }

    @GetMapping("/findRpProduceByBarcode")
    public Msg findRpProduceByBarcode(@RequestParam String ppbarcode){
        return Msg.success("data", rpProduceService.findRpProduceByBarcode(ppbarcode));
    }

    @GetMapping("/findRpProduceBySubBarcode")
    public Msg findRpProduceBySubBarcode(@RequestParam String ppbarcode){
        return Msg.success("data", rpProduceService.findRpProduceBySubBarcode(ppbarcode));
    }

}
